package com.adroiti.texasholdem.engine.combinations;

import java.util.LinkedList;
import java.util.List;

import com.adroiti.texasholdem.Card;
import com.adroiti.texasholdem.Combination;

public abstract class AbstractCombination implements Combination,
		Comparable<Combination> {

	@Override
	public int compareTo(Combination o) {
		if (o.getCombinationRank() > this.getCombinationRank()) {
			return -1;
		} else if (o.getCombinationRank() < this.getCombinationRank())
			return 1;
		else return 0;
	}

	/**
	 * 
	 * @param cards
	 * @return Returns highest rank of given card list
	 */
	protected int getHighestRank(List<Card> cards) {
		int num = 0;
		int cardRank = 0;
		for (Card card : cards) {
			if (num < (cardRank = card.getRank())) {
				num = cardRank;
			}
		}

		return num;

	}

	protected int getHighestRank(List<Card> player, List<Card> table) {
		List<Card> cards = new LinkedList<Card>(player);
		cards.addAll(table);
		return getHighestRank(cards);
	}

}
